//
//  NSString+ZQNSString.m
//  柳州微博
//
//  Created by Apple_Lzzy45 on 16/10/29.
//  Copyright © 2016年 Apple_Lzzy40. All rights reserved.
//

#import "NSString+ZQNSString.h"

@implementation NSString (ZQNSString)
/**
 *  获得字符串的尺寸
 *
 *  @param text 字符串
 *  @param font 字体类型
 *
 *  @return 尺寸
 */
-(CGSize)sizeWithText:(UIFont *)font
{
    //属性字典
    NSMutableDictionary  * attrs=[NSMutableDictionary dictionary];
    attrs[NSFontAttributeName]=font;
    //获得字符串的尺寸
    CGSize maxSize=CGSizeMake(MAXFLOAT, MAXFLOAT);
    return [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
    
}

-(CGSize)sizeWithText:(UIFont *)font maxW:(CGFloat)maxW
{
    //属性字典
    NSMutableDictionary  * attrs=[NSMutableDictionary dictionary];
    attrs[NSFontAttributeName]=font;
    //获得字符串的尺寸
    CGSize maxSize=CGSizeMake(maxW, MAXFLOAT);
    return [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}

@end
